<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<el-form-item label="运营商" prop="operatoruid">
					<el-select v-model="filters.operatoruid" clearable filterable collapse-tags placeholder="请选择运营商">
						<el-option value="0" label="全部">全部</el-option>
						<el-option
								v-for="item in operator"
								:key="item.operatoruid"
								:label="item.operatorname"
								:value="item.operatoruid">
						</el-option>
					</el-select>
				</el-form-item>

				<el-form-item label="省份" prop="provinceuuid">
					<el-select v-model="filters.provinceuuid" clearable filterable collapse-tags placeholder="请选择省份">
						<el-option value="0" label="全部">全部</el-option>
						<el-option
								v-for="item in info"
								:key="item.provinceuuid"
								:label="item.provincename"
								:value="item.provinceuuid">
							<span style="float: left">{{ item.provincename }}</span>
							<span style="float: right; color: #8492a6; font-size: 13px">{{ item.label }}</span>
						</el-option>
					</el-select>
				</el-form-item>

				<!--				<el-form-item label="城市">-->
				<!--					<el-select v-model="filters.cityName" clearable filterable placeholder="请选择地市">-->
				<!--						<el-option-->
				<!--								v-for="item in infoFilters"-->
				<!--								:key="item.cityName"-->
				<!--								:label="item.cityName"-->
				<!--								:value="item.cityName">-->
				<!--						</el-option>-->
				<!--					</el-select>-->
				<!--				</el-form-item>-->

				<el-form-item label="业务类型" prop="busuuid">
					<el-select v-model="filters.busuuid" clearable filterable placeholder="请选择业务类型">
						<el-option value="0" label="全部">全部</el-option>
						<el-option
								v-for="item in bus"
								:key="item.busuuid"
								:label="item.busname"
								:value="item.busuuid">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="分销商" prop="useruuid">
					<el-select v-model="filters.downId" clearable placeholder="请选择分销商" filterable >
						<el-option value="0" label="全部">全部</el-option>
						<el-option
								v-for="item in users"
								:key="item.user.useruuid"
								:label="item.user.username"
								:value="item.user.useruuid">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="供货商" prop="useruuid"  >
					<el-select v-model="filters.upId" clearable placeholder="请选择供货商" filterable filterable >
						<el-option value="0" label="全部">全部</el-option>
						<el-option
								v-for="item in userUps"
								:key="item.user.useruuid"
								:label="item.user.username"
								:value="item.user.useruuid">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="面值">
					<!--                    <el-input v-model="filters.downfacevalue" clearable placeholder="面值"></el-input>-->
					<el-select v-model="filters.downfacevalue" clearable filterable   placeholder="请面值">
						<el-option value="0" label="全部">全部</el-option>
						<el-option
								v-for="item in downfacevalues"
								:key="item.id"
								:label="item.id"
								:value="item.id">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="queryStrategyPage">查询</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
		<el-table :data="mobiles" highlight-current-row v-loading="listLoading" border max-height="620" style="width: 100%;">
			<el-table-column type="index" width="80" label="编号">
			</el-table-column>
			<el-table-column prop="operatorName" label="运营商" show-overflow-tooltip  >
			</el-table-column>
			<el-table-column prop="provinceName" label="省份" show-overflow-tooltip >
			</el-table-column>
			<el-table-column prop="busname" label="业务类型"  show-overflow-tooltip>
			</el-table-column>
			<el-table-column prop="status" label="面值"  show-overflow-tooltip>
			</el-table-column>
			<el-table-column prop="userDown" label="分销名称" show-overflow-tooltip >
			</el-table-column>
			<el-table-column prop="productName" label="分销产品名称"  show-overflow-tooltip>
			</el-table-column>
			<el-table-column prop="downdiscount" label="分销折扣"  show-overflow-tooltip>
			</el-table-column>
			<el-table-column prop="userUp" label="供货名称"  show-overflow-tooltip>
			</el-table-column>
			<el-table-column prop="upName" label="供货产品名称" show-overflow-tooltip >
			</el-table-column>
			<el-table-column prop="updiscount" label="供货折扣"  show-overflow-tooltip>
			</el-table-column>
			<el-table-column prop="orderSort" label="执行顺序"  show-overflow-tooltip>
			</el-table-column>
			<el-table-column label="操作"   fixed="right"width="200">
				<template scope="scope" >
					<el-input-number v-model="scope.row.orderSort" controls-position="right"  @change="handleChange(scope.row)" :min="1" :max="100"></el-input-number>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination
				@current-change="handleCurrentChange"
				@size-change="handleSizeChange"
				layout="total,sizes,prev, pager, next"
				:total="total">
		</el-pagination>



	</section>
</template>

<script>
	import util from '../../common/js/util'
	import {
		queryStrategyPage,
		findAllUpShopInfo,
		findAllDownShopInfo,
		updateStrategy,
		findAllChannel, findAllBus, findOpeProBusShop
	} from '../../api/api';
	import moment from 'moment';
	export default {
		data() {
			return {
				filters: {
					upId:'',
					downfacevalue:'',
					downId:'',
					provinceuuid: '',
					busuuid: '',
					status: '' ,
					operatoruid: ''
				},
				users: [],
				num: 1,
				mobiles:[],
				userUps:[],
				operator: [],
				downfacevalues:[],
				info: [],
				bus: [],
				total: 0,
				start:0,
				pageSize:10,
				listLoading: false,
			}
		},
		methods: {
			findAllDownShopInfo:function(){
				let para = {useruuid: JSON.parse(sessionStorage.getItem("user")).useruuid};
				findAllDownShopInfo(para).then(datas => {
					let {message, code, data} = datas;
					if (code !== "0") {
						this.$message({
							message: message,
							type: 'error'
						});
					} else {
						if(data){
							this.users = data;
						}
					}
				});
			},
			findAllUpShopInfo:function(){
				let para = {
					test:''
				};
				findAllUpShopInfo(para).then(datas =>{
					let {message, code, data} = datas;
					if (code !== "0") {
						this.$message({
							message: message,
							type: 'error'
						});
					} else {
						this.userUps = data;
					}
				});
			},
			queryStrategyPage() {
				let para = {
					start: this.start+1,
					pageSize:this.pageSize,
					userUp:this.filters.upId,
					userDown:this.filters.downId,
					provinceuuid:  this.filters.provinceuuid == "0" ? "" : this.filters.provinceuuid,
					busuuid: this.filters.busuuid == "0" ? "" : this.filters.busuuid,
					status: (this.filters.downfacevalue == "0" || this.filters.downfacevalue.length == 0)? "" : this.filters.downfacevalue  ,
					operatoruid: this.filters.operatoruid == "0" ? "": this.filters.operatoruid,
				};
				this.listLoading = true;
				queryStrategyPage(para).then((datas) => {
					this.listLoading = false;
					let { message, code, data } = datas;
					if (code !== "0") {
						this.$message({
							message: message,
							type: 'error'
						});
					} else {
						this.mobiles = data.result;
						this.total = data.totalCount;
					}
				});
			}
			,handleCurrentChange:function(val){
				this.start = val - 1;
				this.queryStrategyPage();
			},
			handleSizeChange:function(val){
				this.pageSize = val;
				this.queryStrategyPage();
			},
			findAllChannel(){
				let para = {
					province : ""
				};
				findAllChannel(para).then((datas) => {
					this.addLoading = false;
					let { message, code, data } = datas;
					if (code !== "0") {
						this.$message({
							message: message,
							type: 'error'
						});
					}else if(data){
						data.forEach(item =>{
							this.downfacevalues.push({id:item,value:item});
						});
					}
				});
			}, findAllBus: function () {
				let para = {useruuid: ''};
				findAllBus(para).then(datas => {
					let {message, code, data} = datas;
					if (code !== "0") {
						this.$message({
							message: message,
							type: 'error'
						});
					} else {
						this.bus = data;
					}
				});
			},
			findOpeProBusShop(){
				let para = {sdffds: ''};
				findOpeProBusShop(para).then(datas => {
					let {message, code, data} = datas;
					if (code !== "0") {
						this.$message({
							message: message,
							type: 'error'
						});
					} else {
						this.operator = data.operator;
						this.info = data.info;
						this.bus = data.bus;
					}
				});
			},
			handleChange(value) {
				console.log(value);
				updateStrategy(value).then(datas => {
					let {message, code, data} = datas;
					if (code !== "0") {
						this.$message({
							message: message,
							type: 'error'
						});
					} else {
						this.$message({
							message: '操作成功',
							type: 'info'
						});
						this.queryStrategyPage();
					}
				});
			}
		},
		mounted() {
			this.findAllChannel();
			this.findAllDownShopInfo();
			this.findAllUpShopInfo();
			this.findOpeProBusShop();
			this.queryStrategyPage();
		}
	}

</script>

<style scoped>

</style>
